home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Vault: The Gold Collection
/
Software Vault - The Gold Collection (American Databankers) (1993).ISO
/
cdr30
/
hercb21.zip
/
HERCPIXL.C
< prev
next >
Wrap
Text File
|
1993-05-03
|
5KB
|
242 lines
/*
* HERCPIXL.C
* Dave Tutelman - last modified 8/88
*
* This is a set of basic graphic routines for the Hercules
* Board (or at least the SuperComputer version of it; I assume
* that they work with the real thing).
* alfa () puts us in alphanumeric mode.
* grafix (mode) puts us in some graphics mode.
* pixel (x,y,val) puts a pixel at <x,y>. Bright dot if
* val=1, dark dot if val=0.
* dchar (x,y,c) puts character "c" at <x,y>. Note that
* character raster is 90 x 29.
* nchar (x,y,c,n) puts "n"copies of "c" at <x,y>.
* setattr (attr) sets the attribute for any characters
* written by dchar().
* hputc (c) puts character "c" at current cursor,
* using BIOS TTY write function.
* hputs (s) puts string "s" starting at current cursor.
* swpage (page) switches to a different page.
* scroll (top,left,bottom,right,size,attr)
* scroll an area of the screen.
* waitkey () just waits till a key is pressed.
*
* Actually, the routines should work with any board, since the
* BIOS calls are used throughout. It's Hercules-specific only
* because I've defined the graphics and alpha modes for my
* Hercules BIOS.
*
* Making BIOS calls from C must be done in a compiler-dependent
* way. The code below shows styles for three different compilers:
* - Microsoft C uses int86() and the union REGS variables.
* - Turbo C uses int86() and the union REGS, but also supports
* geninterrupt() and _AX, _BX, ...
* - DeSmet C uses _doint() and _rax, _rbx, ...
* This file compiles under Turbo C, and provides enough examples
* so that you should be able to port it to Microsoft or DeSmet.
*/
#define TURBO
/* Define the correspondence between DeSmet and Turbo calls */
#ifdef TURBO
# include <dos.h>
# define _doint geninterrupt
# define _rax _AX
# define _rbx _BX
# define _rcx _CX
# define _rdx _DX
#endif
#define VIDI 0x10 /* video interrupt, normally 10H */
#define KBD 0x16 /* keyboard interrupt */
#define ALFA_MODE 7 /* monochrome alpha mode */
int page = 0;
unsigned char current_attr = 07;
#ifndef TURBO
extern unsigned _rax,_rbx,_rcx,_rdx;
#endif
/*
* This puts us back in alphanumeric mode
*/
alfa ()
{
_rax = ALFA_MODE; /* mono 80-col mode */
_doint ( VIDI ); /* set mode */
}
/*
* This one switches us to a graphics mode
*/
grafix (mode)
int mode;
{
_rax = mode; /* herc grafix mode */
_doint ( VIDI ); /* set mode */
}
/*
* This writes a pixel at (x,y), where (0,0) is the upper-left
* corner of the screen. If val = 0 then the pixel is erased.
*/
pixel (x, y, val)
int x, y, val;
{
_rax = 0x0C00 + val; /* function 12 */
_rcx = x;
_rdx = y;
_doint ( VIDI ); /* set mode */
}
/*
* dchar (x,y,c) puts character "c" at <x,y>. Note that
* character raster is 90 x 25.
*/
setattr (color)
unsigned char color;
{
current_attr = color;
}
dchar (x,y,c)
int x,y;
char c;
{
#ifdef TURBO
union REGS rr;
rr.h.ah = 2; /* move cursor function */
rr.h.dh = y;
rr.h.dl = x;
rr.h.bh = page;
int86 (VIDI, &rr, &rr);
rr.h.ah = 9; /* write character function */
rr.h.al = c;
rr.x.cx = 1;
rr.h.bh = page;
rr.h.bl = current_attr;
int86 (VIDI, &rr, &rr);
#else
_rax = 2*256; /* AH=Fn#2 */
_rdx = 256*y + x; /* DH=row, DX=col */
_rbx = page * 256; /* BH=page */
_doint (VIDI); /* set cursor */
_rax = 0x900 + c; /* AH=Fn#9, AL=char */
_rcx = 1; /* CX=count */
_rbx = page*256 + current_attr; /* BH=page, BL=attr */
_doint (VIDI); /* write character */
#endif
}
nchar (x,y,c,n)
int x,y, n;
char c;
{
#ifdef TURBO
union REGS rr;
rr.h.ah = 2; /* move cursor function */
rr.h.dh = y;
rr.h.dl = x;
rr.h.bh = page;
int86 (VIDI, &rr, &rr);
rr.h.ah = 9; /* write character function */
rr.h.al = c;
rr.x.cx = n;
rr.h.bh = page;
rr.h.bl = current_attr;
int86 (VIDI, &rr, &rr);
#else
_rax = 2*256; /* AH=Fn#2 */
_rdx = 256*y + x; /* DH=row, DX=col */
_rbx = page * 256; /* BH=page */
_doint (VIDI); /* set cursor */
_rax = 0x900 + c; /* AH=Fn#9, AL=char */
_rcx = 1; /* CX=count */
_rbx = page*256 + current_attr; /* BH=page, BL=attr */
_doint (VIDI); /* write character */
#endif
}
hputc (c)
char c;
{
union REGS rr;
rr.h.ah = 14; /* TTY write function */
rr.h.al = c;
int86 (VIDI, &rr, &rr);
}
hputs (s)
char *s;
{
char *p;
for (p=s; *p!='\0'; p++)
hputc (*p);
}
/*
* This one switches us to a different page, without changing
* the contents of that page.
*/
swpage (newpage)
int newpage;
{
page = newpage;
_rax = 0x500 + page; /* new page function */
_doint ( VIDI ); /* interrupt call */
}
scroll (top,left,bottom,right,size,attr)
int top,left,bottom,right;
int size,attr;
{
union REGS rr;
rr.h.ch = (char) top;
rr.h.cl = (char) left;
rr.h.dh = (char) bottom;
rr.h.dl = (char) right;
rr.h.bh = (char) attr;
if (size < 0) { /* scroll down */
rr.h.al = -size;
rr.h.ah = 7;
}
else { /* scroll up */
rr.h.al = size;
rr.h.ah = 6;
}
int86 (0x10, &rr, &rr);
}
waitkey ()
{
_rax = 0; /* keyboard blocking read function */
_doint (KBD);
}